/**
 */
package OBSL.impl;

import OBSL.MediationLink;
import OBSL.OBSLPackage;
import OBSL.RelatorIndividual;
import OBSL.RoleIndividual;

import RefOntoUML.Mediation;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Mediation Link</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link OBSL.impl.MediationLinkImpl#getMediation <em>Mediation</em>}</li>
 *   <li>{@link OBSL.impl.MediationLinkImpl#getRelator <em>Relator</em>}</li>
 *   <li>{@link OBSL.impl.MediationLinkImpl#getRole <em>Role</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MediationLinkImpl extends MinimalEObjectImpl.Container implements MediationLink {
	/**
	 * The cached value of the '{@link #getMediation() <em>Mediation</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMediation()
	 * @generated
	 * @ordered
	 */
	protected Mediation mediation;

	/**
	 * The cached value of the '{@link #getRole() <em>Role</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRole()
	 * @generated
	 * @ordered
	 */
	protected RoleIndividual role;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MediationLinkImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return OBSLPackage.Literals.MEDIATION_LINK;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Mediation getMediation() {
		if (mediation != null && mediation.eIsProxy()) {
			InternalEObject oldMediation = (InternalEObject)mediation;
			mediation = (Mediation)eResolveProxy(oldMediation);
			if (mediation != oldMediation) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, OBSLPackage.MEDIATION_LINK__MEDIATION, oldMediation, mediation));
			}
		}
		return mediation;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Mediation basicGetMediation() {
		return mediation;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMediation(Mediation newMediation) {
		Mediation oldMediation = mediation;
		mediation = newMediation;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.MEDIATION_LINK__MEDIATION, oldMediation, mediation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RelatorIndividual getRelator() {
		if (eContainerFeatureID() != OBSLPackage.MEDIATION_LINK__RELATOR) return null;
		return (RelatorIndividual)eInternalContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRelator(RelatorIndividual newRelator, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newRelator, OBSLPackage.MEDIATION_LINK__RELATOR, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRelator(RelatorIndividual newRelator) {
		if (newRelator != eInternalContainer() || (eContainerFeatureID() != OBSLPackage.MEDIATION_LINK__RELATOR && newRelator != null)) {
			if (EcoreUtil.isAncestor(this, newRelator))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newRelator != null)
				msgs = ((InternalEObject)newRelator).eInverseAdd(this, OBSLPackage.RELATOR_INDIVIDUAL__MEDIATES, RelatorIndividual.class, msgs);
			msgs = basicSetRelator(newRelator, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.MEDIATION_LINK__RELATOR, newRelator, newRelator));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RoleIndividual getRole() {
		if (role != null && role.eIsProxy()) {
			InternalEObject oldRole = (InternalEObject)role;
			role = (RoleIndividual)eResolveProxy(oldRole);
			if (role != oldRole) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, OBSLPackage.MEDIATION_LINK__ROLE, oldRole, role));
			}
		}
		return role;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RoleIndividual basicGetRole() {
		return role;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRole(RoleIndividual newRole) {
		RoleIndividual oldRole = role;
		role = newRole;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.MEDIATION_LINK__ROLE, oldRole, role));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.MEDIATION_LINK__RELATOR:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetRelator((RelatorIndividual)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.MEDIATION_LINK__RELATOR:
				return basicSetRelator(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case OBSLPackage.MEDIATION_LINK__RELATOR:
				return eInternalContainer().eInverseRemove(this, OBSLPackage.RELATOR_INDIVIDUAL__MEDIATES, RelatorIndividual.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case OBSLPackage.MEDIATION_LINK__MEDIATION:
				if (resolve) return getMediation();
				return basicGetMediation();
			case OBSLPackage.MEDIATION_LINK__RELATOR:
				return getRelator();
			case OBSLPackage.MEDIATION_LINK__ROLE:
				if (resolve) return getRole();
				return basicGetRole();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case OBSLPackage.MEDIATION_LINK__MEDIATION:
				setMediation((Mediation)newValue);
				return;
			case OBSLPackage.MEDIATION_LINK__RELATOR:
				setRelator((RelatorIndividual)newValue);
				return;
			case OBSLPackage.MEDIATION_LINK__ROLE:
				setRole((RoleIndividual)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case OBSLPackage.MEDIATION_LINK__MEDIATION:
				setMediation((Mediation)null);
				return;
			case OBSLPackage.MEDIATION_LINK__RELATOR:
				setRelator((RelatorIndividual)null);
				return;
			case OBSLPackage.MEDIATION_LINK__ROLE:
				setRole((RoleIndividual)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case OBSLPackage.MEDIATION_LINK__MEDIATION:
				return mediation != null;
			case OBSLPackage.MEDIATION_LINK__RELATOR:
				return getRelator() != null;
			case OBSLPackage.MEDIATION_LINK__ROLE:
				return role != null;
		}
		return super.eIsSet(featureID);
	}

} //MediationLinkImpl
